package com.chainyoung.trademarket.mvp.model;

import com.chainyoung.common.appcommon.db.DbConstant;
import com.chainyoung.common.appcommon.entity.HdWalletCache;
import com.chainyoung.common.appcommon.entity.Version;
import com.chainyoung.common.appcommon.hdwallet.HdWalletDAO;
import com.chainyoung.common.bean.UserInfo;
import com.chainyoung.common.di.scope.ActivityScope;
import com.chainyoung.common.integration.IRepositoryManager;
import com.chainyoung.common.mvp.BaseModel;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmperson.api.PersonService;
import com.chainyoung.component_tmperson.entity.MyTotalAsset;
import com.chainyoung.trademarket.api.MainService;
import com.chainyoung.trademarket.entity.Ad;
import com.chainyoung.trademarket.mvp.contract.MainContract;

import java.util.List;
import java.util.TreeMap;

import javax.inject.Inject;

import io.reactivex.Flowable;

@ActivityScope
public class MainModel extends BaseModel implements MainContract.Model{

    private HdWalletDAO DAO = new HdWalletDAO(mRepositoryManager.obtainRealmConfig(DbConstant.DB_NAME));

    @Inject
    public MainModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public Flowable<UserInfo> getUserInfo(TreeMap<String, Object> map) {
        return mRepositoryManager.obtainRetrofitService(MainService.class)
                .getUserInfo(map)
                //.compose(RxUtils.<BaseResponse<UserInfo>>rxSchedulerHelper())
                .compose(RxUtils.<UserInfo>handleResult());
    }

    @Override
    public Flowable<Version> checkUpdate() {
        return mRepositoryManager.obtainRetrofitService(PersonService.class)
                .checkUpdate()
                .compose(RxUtils.<Version>handleResult());
    }

    @Override
    public Flowable<HdWalletCache> addHdWalletCache(HdWalletCache item) {
        return DAO.addHdWalletCache(item);
    }

    @Override
    public Flowable<List<HdWalletCache>> getAllHdWalletCaches(String coinType) {
        return DAO.getHdWalletCaches(coinType);
    }



//    @Override
//    public Flowable<List<Ad>> getIndexAds(TreeMap<String, Object> map) {
//        return mRepositoryManager.obtainRetrofitService(MainService.class)
//                .getIndexAds(map)
//                //.compose(RxUtils.<BaseResponse<UserInfo>>rxSchedulerHelper())
//                .compose(RxUtils.<List<Ad>>handleResult());
//    }

//    @Override
//    public Flowable<MyTotalAsset> getTotalAsset(TreeMap<String, Object> map) {
//        return mRepositoryManager.obtainRetrofitService(MainService.class)
//                .getTotalAsset(map)
//                //.compose(RxUtils.<BaseResponse<UserInfo>>rxSchedulerHelper())
//                .compose(RxUtils.<MyTotalAsset>handleResult());
//    }
}
